-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Implement (m|mun)lockall for Linux and *nix libcs #19203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/std/c.zig
Outdated
// All the Unix-likes except darwin support the call and the flags in a | ||
// consistent way except Linux, which has an extra flag MCL_ONFAULT and has | ||
// non-standard values for the MCL constants on ppc, ppc64, and sparc. | ||
pub usingnamespace switch (native_os) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#19195 (comment) applies here as well.
@Vexu - Sorry, my updated commit is failing tests on windows and others now. This is because it included a smoke test in I'm not yet sure how to deal with this properly, but it seems like maybe I should bring this testing topic up more-generally back over in #19214 . I suspect none of the commits there really addressed this, because all of the cases that were platform-conditional in those commits also lacked tests. |
related: andrew just opened #19352 How about this pattern, makes the test gate relatively simple: const native_os = @import("builtin").os.tag;
// suggest put this in lib/std/c.zig between
// `pub const fstat = ....` and `pub const stat = ...`
// many conditionals there, and in alphabetic order.
pub const mlockall = switch (native_os) {
.linux, .freebsd, .netbsd, .openbsd, .dragonfly, .solaris => private.mlockall,
else => {},
};
// this struct already present at bottom of lib/std/c.zig
const private = struct {
pub extern "c" fn mlockall(flags: c_int) c_int;
};
test {
if (@TypeOf(mlockall) == void) return error.SkipZigTest;
// use it
_ = &mlockall;
} |
That does seem like it should work. I do wonder though, in light of #19352, whether |
New push basically does things as @mikdusan suggested. I also used the void TypeOf check pattern to return an |
Note also this should wait to be rebased+amended around whatever comes of #19354 as well. |
Marking as draft for now, because I'm betting I should just wait for https://github.com/ziglang/zig/tree/linux-type-safety to land (I assume it will shortly, since this seems to be an area of focus!) and then rework the In any case, another interim push incoming shortly that updates for latest master (incl the new I still suspect some will hate the current There's a lot of layers involved here, and the existing related examples in master's std still have a blend of different approaches that haven't coalesced into a single consistent design pattern that works for all cases and avoids all the obvious pitfalls (untestability, late link-time failures, copying platform-support lists around N places and letting them bitrot, etc). |
This is just like std.testing.expectError, but takes a slice of multiple errors as an "[]const anyerror" argument with the expectation that any one of those errors should occur.
Ok, after some more thinking and conversation elsewhere, I think I've come around to a decent pattern with the latest push. This seems about as elegant as I can make things without causing other undesirable tradeoffs! There's no Basically, rather than trying to put the libc parts together in At the POSIX layer, we have an explicit target native_os list that we support (which seems common and reasonable as a pattern), and we return This seems like a worthy pattern for implementing similar things (and maybe refactoring some of the existing sys/libc/posix calls towards). |
still a draft, no update in 30+ days |
No description provided.